/******************************************************************************
 *  TWI (I2C) serial bus functions (for master mode)
 ******************************************************************************
 *  To initialize TWI (I2C) bus (set it's frequency to 100kHz)
 *  you should do the following:
 *
 *      TWSR = 0;
 *      TWBR = (F_CPU / 100000UL - 16) / 2;
 *
 *  All functions returns non-zero value to indicate error.
 ******************************************************************************/

#ifndef _TWI_UTILS_H_
#define _TWI_UTILS_H_
 
#include <util/twi.h>

/******************************************************************************
 * Starts communication over TWI bus (master mode)
 ******************************************************************************/
int twiStart(void);

/******************************************************************************
 * Selects device on bus to which send data
 ******************************************************************************/
int twiSelect(unsigned char);

/******************************************************************************
 * Reads byte from previously selected address
 ******************************************************************************/
int twiRead(unsigned char *, int);

/******************************************************************************
 * Writes byte to the previously selected address
 ******************************************************************************/
int twiWrite(unsigned char);

/******************************************************************************
 * Stops communication through TWI bus
 ******************************************************************************/
void twiStop(void);
 
#endif
